package se.thoka.twt.client.utils;

import java.util.Collection;
import java.util.List;

import se.thoka.twt.client.event.HasListItemClickedHandlers;
import se.thoka.twt.client.event.HasListItemMouseOutHandlers;
import se.thoka.twt.client.event.HasListItemMouseOverHandlers;

import com.google.gwt.user.client.ui.IsWidget;

public interface TWTListBase<LI extends IsWidget> extends HasListItemClickedHandlers<LI>, HasListItemMouseOverHandlers<LI>, HasListItemMouseOutHandlers<LI> {
	/**
	 * Adds a widget to this list.
	 * 
	 * @param listItem The list item widget.
	 */
	void add(LI listItem);

	/**
	 * Adds a collection of widgets to this list.
	 * 
	 * @param listItems The list item widgets to add.
	 */
	void addAll(Collection<LI> listItems);

	/**
	 * Checks if this list contains the supplied item widget.
	 * 
	 * @param listItem The list item width to find.
	 * @return <code>true</code> if found.
	 */
	boolean contains(LI listItem);

	/**
	 * Returns the list item widget at a specific list index.
	 * 
	 * @param index The list index.
	 * @return The list item widget.
	 */
	LI getItem(int index);

	/**
	 * Returns the number of list items.
	 * 
	 * @return The number of list items.
	 */
	int getItemCount();

	/**
	 * Returns the list index of the supplied list item widget.
	 * 
	 * @param listItem The list item widget.
	 * @return The list index.
	 */
	int getItemIndex(LI listItem);

	/**
	 * Inserts a widget to this list at the supplied index.
	 * 
	 * @param listItem The list item widget.
	 * @param index The index.
	 */
	void insert(LI listItem, int index);

	/**
	 * @return <code>true</code> if list is currently empty
	 */
	boolean isEmpty();

	/**
	 * Removes the widget at the supplied list index position.
	 * 
	 * @param listIndex The list index position, e.g.
	 *            <code>{0...({@link #getItemCount()} - 1)}</code>.
	 * @return <code>true</code> if successfully removed.
	 */
	boolean remove(int listIndex);

	/**
	 * Removes the supplied list item widget from the list.
	 * 
	 * @param listItem The list item widget.
	 * @return <code>true</code> if successfully removed.
	 */
	boolean remove(LI listItem);

	/**
	 * Removes a collection of list item widgets from the list.
	 * 
	 * @param listItems The list item widgets to remove.
	 */
	void removeAll(Collection<LI> listItems);

	/**
	 * Returns a sub list of the underlying list item widgets.
	 * 
	 * @param fromIndex The from index.
	 * @param toIndex The to index.
	 * @return The sub list of list item widgets.
	 */
	List<LI> subList(int fromIndex, int toIndex);

	/**
	 * Clears this list from all list item widgets.
	 */
	void clear();

	/**
	 * Adds a style dependent name on a list item.
	 * 
	 * @param index The list item index.
	 * @param styleSuffix The style suffix.
	 * @return <code>true</code> if style was successfully added.
	 */
	boolean addListItemStyleDependentName(int index, String styleSuffix);

	/**
	 * Adds a style dependent name on a list item.
	 * 
	 * @param listItem The list item, must not be <code>null</code>.
	 * @param styleSuffix The style suffix.
	 * @return <code>true</code> if style was successfully added.
	 */
	boolean addListItemStyleDependentName(LI listItem, String styleSuffix);

	/**
	 * Removes a style dependent name from a list item.
	 * 
	 * @param index The list item index.
	 * @param styleSuffix The style suffix.
	 * @return <code>true</code> if style was successfully added.
	 */
	boolean removeListItemStyleDependentName(int index, String styleSuffix);

	/**
	 * Removes a style dependent name from a list item.
	 * 
	 * @param listItem The list item, must not be <code>null</code>.
	 * @param styleSuffix The style suffix.
	 * @return <code>true</code> if style was successfully removed.
	 */
	boolean removeListItemStyleDependentName(LI listItem, String styleSuffix);
}
